package com.daluzy.chmanager.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.daluzy.chmanager.R;
import com.daluzy.chmanager.bean.Area;
import com.daluzy.chmanager.bean.TestPoint;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class AreaAdapter extends RecyclerView.Adapter<AreaAdapter.MyViewHolder> {



    private Context context;
    private List<Area> myData = new ArrayList<>();

    public AreaAdapter(Context context, List<Area> myData) {
        this.context = context;
        this.myData = myData;
    }

    @NonNull
    @Override
    public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.adapter_area_item_daluzy, parent, false);
        return new MyViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
        Area area = myData.get(position);
        holder.tvSchoolName.setText(area.getArea_school());
        holder.tvAreaName.setText(area.getArea_name());

        List<TestPoint> testPoints = area.getTestPointList();
        if (testPoints != null && testPoints.size() > 0) {
            holder.llTestPoint.setVisibility(View.VISIBLE);
            holder.tvAreaTem.setText(testPoints.get(0).getPoint_tem());
            TestPointAdapter testPointAdapter = new TestPointAdapter(context, testPoints);
            holder.rvPointData.setLayoutManager(new LinearLayoutManager(context));
            holder.rvPointData.setAdapter(testPointAdapter);
        }else {
            holder.llTestPoint.setVisibility(View.GONE);
        }

    }

    @Override
    public int getItemCount() {
        return myData.size();
    }

    class MyViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.tv_school_name)
        TextView tvSchoolName;
        @BindView(R.id.tv_area_name)
        TextView tvAreaName;
        @BindView(R.id.tv_area_tem)
        TextView tvAreaTem;
        @BindView(R.id.tv_point_name)
        TextView tvPointName;
        @BindView(R.id.tv_point_tem)
        TextView tvPointTem;
        @BindView(R.id.tv_test_person)
        TextView tvTestPerson;
        @BindView(R.id.ll_test_point)
        LinearLayout llTestPoint;
        @BindView(R.id.rv_point_data)
        RecyclerView rvPointData;

        public MyViewHolder(@NonNull View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
